var urltest = sessionStorage.getItem("urltest");
console.log(urltest)
//$('.header img').click(function() {
//	window.location.href = "smart_meter.html"
//})

$(function() {
	var address = sessionStorage.getItem("address");
	var address = JSON.parse(address);
	var identityCard = sessionStorage.getItem("ID_card");
	var obj = {
		identityCard: identityCard
	};
	var req = JSON.stringify(obj);
	console.log(urltest)
	$.ajax({
		contentType: "application/json; charset=utf-8",
		type: "POST",
		url: urltest + "notcheck/queryOrderPage",
		data: req,
		async: false,
		dataType: "json",
		beforeSend: function() {
			$("#showResult").show();
		},
		success: function(msg) {
			console.log(msg);
			var bb = msg.obj;
			createShowingTable(bb);
			if(msg.resCode == 200) {
				$("#showResult").remove();
				console.log(msg);
				var bb = msg.obj;
				createShowingTable(bb);
			} else if(msg.resCode == 404) {
				window.location.href = "jq404.html";
			} else {
				//				alert(msg.resmsg);
				$("#tips").html(msg.resmsg);
				$('#myModal_tips').modal('show');
			}
		},
		error: function() {
			//			alert(msg.resmsg);
			$("#tips").html(msg.resmsg);
			$('#myModal_tips').modal('show');
			$("#showResult").remove();
		}
	});
})

function createShowingTable(bb) {
	//获取后台传过来的jsonData,并进行解析  
	//此处需要让其动态的生成一个table并填充数据 
	var tableStr = "";
	var len = bb.showRecords.length;
	for(var i = 0; i < len; i++) {
		function formatDate(now) {
			var year = now.getFullYear();
			var month = now.getMonth() + 1;
			var date = now.getDate();
			var hour = now.getHours();
			var minute = now.getMinutes();
			var second = now.getSeconds();
			return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
		}
		var rctualPayAmount = bb.showRecords[i].rctualPayAmount * 0.01;
		var d = new Date(bb.showRecords[i].createTime);
		var pp = formatDate(d);
		//		var state="";
		//		if(bb.showRecords[i].payState="BOB"){
		//			state="充值成功";
		//		}else{
		//			state = bb.showRecords[i].payState;
		//		}
		var returnCode = "";
		if(bb.showRecords[i].returnCode == null || bb.showRecords[i].returnCode == undefined || bb.showRecords[i].returnCode == "") {
			returnCode = "";
		} else {
			returnCode = bb.showRecords[i].returnCode;
		}

		tableStr = tableStr + '<tr>' +
			'<td>' + returnCode + '</td>' +
			'<td>' + bb.showRecords[i].roomId + '</td>' +
			'<td>' + bb.showRecords[i].createTime + '</td>' +
			'<td>' + rctualPayAmount + '</td>' +
			'</tr>'

	}
	//将动态生成的table添加的事先隐藏的div中.  
	$("#tbbb").html(tableStr);

}